package com.weiaibenpao.demo.chislim.hurui.adapte;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.hurui.bean.FlexibleBean;

import java.util.List;

/**
 * Created by lenovo on 2017/4/11.
 */

public class HrFristAdapter extends BaseAdapter{
    private Context mContext ;
    private List<FlexibleBean.DataBean.ActivitylistBean> lists ;

    public HrFristAdapter(Context context , List<FlexibleBean.DataBean.ActivitylistBean> lists){
        this.mContext = context ;
        this.lists = lists ;
    }

    @Override
    public int getCount() {
            return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHodler viewHodler = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mContext).inflate(R.layout.hr_frist_item, null);
                viewHodler = new ViewHodler();
                viewHodler.title = (TextView) convertView.findViewById(R.id.item_title_tv);
                viewHodler.content = (TextView) convertView.findViewById(R.id.item_messge_tv);
                viewHodler.icon_iv = (ImageView) convertView.findViewById(R.id.icon_image);
                convertView.setTag(viewHodler);
            } else {
                viewHodler = (ViewHodler) convertView.getTag();
            }
            String[] str = lists.get(position).getActivityTitle().split("#");
            viewHodler.content.setText(str[1]);
            viewHodler.title.setText(str[0]);
            Picasso.with(mContext).load(lists.get(position).getActivityImgUrl()).into(viewHodler.icon_iv);
        return convertView;
    }

    public static class ViewHodler{
        ImageView icon_iv ;
        TextView title ;
        TextView content ;
    }
}
